﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Web;
using System.Threading.Tasks;
using System.Data;
using BartonExtension;
using ResponseObject;
using SQLWrapper;
using Model.App;
using Model.Images;
using Model.Weixin;

using Services.Business;
using Services.Common;

namespace iShangMai.Controllers.App
{
    public class BusinessController : ApiController
    {
        [HttpGet]
        public async Task<ZKResponse> GetBusiness(UInt64 uid,UInt64 bid,string token)
        {
            ZKResponse response = new ZKResponse();
            ISMGetSingleBusinessRequest request = new ISMGetSingleBusinessRequest()
            {
                token = token,
                uid = uid,
                bid = bid
            };
            ISMBusinessServiceProvider provider = (ISMBusinessServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.BUSINESS];
            ISMServiceModel model = new ISMServiceModel()
            {
                userinfo = request,
                operationIdentifier = ISMBusinessServiceProvider.GET_SINGLE_BUSINESS
            };
            var result = await provider.doProcess(model);
            response.isProcessSuccess = result.isOperationSuccess;
            response.errMsg = result.errorMsg;
            response.userinfo = result.dbReturningState;
            return response;
        }
        [HttpGet]
        public async Task<ZKResponse> GetBusinesses(UInt64 uid, int page, int pageSize, GetContentType contentType, string parameterState, string token)
        {
            ZKResponse response = new ZKResponse();
            ISMGetBusinessRequest request = new ISMGetBusinessRequest()
            {
                uid = uid,
                page = page,
                pageSize = pageSize,
                token = token,
                type = contentType,
                parameterState = parameterState
            };
            ISMServiceModel model = new ISMServiceModel()
            {
                operationIdentifier = ISMBusinessServiceProvider.GET_BUSINESS,
                userinfo = request
            };
            ISMBusinessServiceProvider provider = (ISMBusinessServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.BUSINESS];
            var result = await provider.doProcess(model);
            response.isProcessSuccess = result.isOperationSuccess;
            response.errMsg = result.errorMsg;
            response.userinfo = result.dbReturningState;
            return response;
        }
        [HttpPost]
        public async Task<ZKResponse> AddNewBizFeed(ISMNewBizRequest request)
        {
            ZKResponse response = new ZKResponse();
            ISMServiceModel model = new ISMServiceModel()
            {
                operationIdentifier = ISMBusinessServiceProvider.ADD_BUSINESS,
                userinfo = request
            };
            ISMBusinessServiceProvider provider = (ISMBusinessServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.BUSINESS];
            ISMServiceResult result = await provider.doProcess(model);
            response.isProcessSuccess = result.isOperationSuccess;
            response.errMsg = result.errorMsg;
            response.userinfo = result.dbReturningState;
            return response;
        }
    }
}
